home *** CD-ROM | disk | FTP | other *** search
- Path: dawn.mmm.com!news
- From: kjhopps@mmm.com (Kevin J Hopps)
- Newsgroups: comp.lang.c++
- Subject: Re: function pointer in C++
- Date: 8 Feb 1996 14:10:54 GMT
- Organization: 3M - St. Paul, MN 55144-1000 US
- Message-ID: <4fd09e$hf3@dawn.mmm.com>
- References: <4f7rd5$6ha@transfer.stratus.com>
- Reply-To: kjhopps@mmm.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- davidm@ssi.stratus.com wrote:
- > I have read the FAQ but do not have it in front of me right now. If
- > this question appears in it, my apologies.
-
- > I am involved with a project to port a ton of C (ANSI and K&R) to
- > C++. This is the first step in migration to an OO architecture.
-
- > The previous programmer used a typedef for a pointer to a function
- > returning void that looks like this:
-
- > typedef void (*PFV)();
-
- > It is used repeatedly through out the code to point to functions
- > that require arguements. The compiler complains about the mismatch
- > in the arguement list Ex:
-
- Yes. Calling a function through a pointer to a different type of
- function results in undefined behavior. But it is safe to cast
- to the proper function type and then call.
-
- > static void call_thru (int argc, char *argv[]);
-
- > PFV netx_entry_point = call_thru;
-
- > (Note: they are not all just (int, char**)).
-
- > I have gone through most of the code and removed the declarations
- > involving PFV and replaced with something like:
-
- > void (*netx_entry_point(int, char**) = call_thru;
-
- > I would like to know if there is a more elegant or perhaps just plain
- > better way to handle this that is not obvious to me.
-
- Correct syntax might be more elegant :-)
-
- If you like the typedef, you might use that for the different types
- of functions:
- typedef void (*ArgcArgvFunc)(int, char**);
- ArgcArgvFunc netx_entry_point = call_thru;
- --
- Kevin J. Hopps e-mail: kjhopps@mmm.com
- 3M Company phone: (612) 737-4643
- 3M Center, Bldg. 235-2D-57 fax: (612) 737-2700
- St. Paul, MN 55144-1000 Opinions are my own. I don't speak for 3M.
- But 3M speaks for me -- I did not write the following line:
-
- Opinions expressed herein are my own and may not represent those of 3M.
-